const Controller = require('egg').Controller
const shortid = require('shortid')

class FileController extends Controller {
  // 上传
  async upload() {
    let tempFile = this.ctx.request.files[0]
    console.log('到达1：', this.ctx.request.files)
    let typeName = tempFile.filename.substr(tempFile.filename.lastIndexOf('.'))
    const res = await this.ctx.upload.put(
      this.app.config.multipart.dir + shortid.generate() + typeName,
      tempFile.filepath
    )
    this.ctx.body = this.ctx.returnStatus.SUCCESS(res)
  }
}

module.exports = FileController
